;;; init-tools.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 gotpl
;;
;; Author: gotpl <631707329@qq.com>
;; Maintainer: gotpl <631707329@qq.com>
;; Created: 2023-08-01 22:10:12
;; Modified: 2024-08-10 22:56:26
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;  Description
;;
;;; Code:

(use-package which-key
  :hook (emacs-startup . which-key-mode)
  :custom
  (which-key-idle-delay 0.5)
  (which-key-add-column-padding 1)
  ;; :config
  ;; (which-key-add-key-based-replacements "<SPC>f" "files")
  )

;; Jump to arbitrary positions

(use-package avy
  ;; integrate with isearch and others
  ;; C-' to select isearch-candidate with avy
  :bind (("M-g M-l" . avy-goto-line)
                    ("M-g M-j" . avy-goto-char-timer))
  :custom
  (avy-background t)
  (avy-all-windows nil)
  (avy-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l ?q ?w ?e ?r ?u ?i ?o ?p))
  ;; overlay is used during isearch, `pre' style makes avy keys evident.
  (avy-styles-alist '((avy-isearch . pre)))
  :config
  (avy-setup-default))

(use-package drag-stuff
  :bind (([M-<left>] . drag-stuff-left)
          ("M-<right>" . drag-stuff-right)
          ("M-<up>" . drag-stuff-up)
          ("M-<down>" . drag-stuff-down))
  :config
  ;; (global-set-key (kbd "M-<left>") 'drag-stuff-left)
  ;; (global-set-key (kbd "M-<right>") 'drag-stuff-right)
  ;; (global-set-key (kbd "M-<up>") 'drag-stuff-up)
  ;; (global-set-key (kbd "M-<down>") 'drag-stuff-down)
  (drag-stuff-mode t)
  )

(use-package general
  :defer t
  )

;; (use-package pdf-tools
;;   )

;; (use-package dirvish
;;   :custom
;;   (dirvish-quick-access-entries ; It's a custom option, `setq' won't work
;;    '(("h" "~/"                            "Home")
;;      ("d" "~/Downloads/"                  "Downloads")
;;      ("p" "~/personal/"                   "personal")
;;      ("l" "~/personal/new_proj/labtask"   "labtask")
;;      ("m" "/mnt/"                         "Drives")
;;      ("t" "~/.local/share/Trash/files/"   "TrashCan")))
;;   :bind ; Bind `dirvish|dirvish-side|dirvish-dwim' as you see fit
;;   (("C-c f" . dirvish-fd)
;;    :map dirvish-mode-map ; Dirvish inherits `dired-mode-map'
;;    ("a"   . dirvish-quick-access)
;;    ("-" . dired-up-directory)
;;    ("f"   . dirvish-file-info-menu)
;;    ("y"   . dirvish-yank-menu)
;;    ("N"   . dirvish-narrow)
;;    ("^"   . dirvish-history-last)
;;    ("h"   . dirvish-history-jump) ; remapped `describe-mode'
;;    ("s"   . dirvish-quicksort)    ; remapped `dired-sort-toggle-or-edit'
;;    ("v"   . dirvish-vc-menu)      ; remapped `dired-view-file'
;;    ("TAB" . dirvish-subtree-toggle)
;;    ("M-f" . dirvish-history-go-forward)
;;    ("M-b" . dirvish-history-go-backward)
;;    ("M-l" . dirvish-ls-switches-menu)
;;    ("M-m" . dirvish-mark-menu)
;;    ("M-t" . dirvish-layout-toggle)
;;    ("M-s" . dirvish-setup-menu)
;;    ("M-e" . dirvish-emerge-menu)
;;    ("M-j" . dirvish-fd-jump)
;;    ("q" . dirvish-quit))
;;   :init
;;   (dirvish-override-dired-mode)
;;   :config
;;   (evil-make-overriding-map dirvish-mode-map 'normal)
;;   ;; (dirvish-peek-mode) ; Preview files in minibuffer
;;   ;; (dirvish-side-follow-mode) ; similar to `treemacs-follow-mode'
;;   (with-eval-after-load 'evil (evil-set-initial-state 'dired-mode 'emacs))
;;   (setq dirvish-mode-line-format
;;         '(:left (sort symlink) :right (omit yank index)))
;;   (setq dirvish-attributes
;;         '(all-the-icons file-time file-size collapse subtree-state vc-state git-msg))
;;   (setq delete-by-moving-to-trash t)
;;   (setq dired-listing-switches
;;         "-l --almost-all --human-readable --group-directories-first --no-group")
  
;;   )

(use-package google-this
  :commands google-this)

;; bug message show Edebug: names-edebug-anon0
(use-package youdao-dictionary
  :bind ("M-m y" . youdao-dictionary-search-at-point-posframe)
  :ensure (:repo "https://github.com/xuchunyang/youdao-dictionary.el"))

;; (use-package async
;;   :ensure (:repo "https://github.com/jwiegley/emacs-async"))

;; (use-package netease-cloud-music
;;   :ensure (:repo "https://github.com/ipyffor/netease-cloud-music.el.git")
;;   :after async
;;   :config
;;   (require 'netease-cloud-music)
;;   (require 'netease-cloud-music-ui)       ;If you want to use the default TUI, you should add this line in your configuration.
;;   (require 'netease-cloud-music-comment)  ;If you want comment feature
;; )

;;; Terminal

(use-package mwim
  :ensure t
  :bind (
         ("C-a" . mwim-beginning-of-code-or-line)
         ("C-e" . mwim-end-of-code-or-line)))

(use-package vterm-toggle
  :ensure t
  :commands (vterm-toggle))

(use-package vterm
  :when (memq window-system '(mac ns x pgtk))
  :commands (vterm)
  :bind (:map vterm-mode-map
              ("C-y" . vterm-yank)
              ("M-y" . vterm-yank-pop)
              ("C-k" . vterm-send-C-k-and-kill))
  :init
  (setq vterm-shell "zsh")
  :config
  (setq vterm-always-compile-module t)
  (defun vterm-send-C-k-and-kill ()
    "Send `C-k' to libvterm, and put content in kill-ring."
    (interactive)
    (kill-ring-save (point) (vterm-end-of-line))
    (vterm-send-key "k" nil nil t)))

;; (use-package vterm-toggle
;;   :when (memq window-system '(mac ns x pgtk))
;;   :bind (([f8] . vterm-toggle)
;;          ([f9] . vterm-compile)
;;          :map vterm-mode-map
;;          ([f8] . vterm-toggle)
;;          ([(control return)] . vterm-toggle-insert-cd))
;;   :config
;;   (setq vterm-toggle-cd-auto-create-buffer nil)
;;   (defvar vterm-compile-buffer nil)
;;   (defun vterm-compile ()
;;     "Compile the program including the current buffer in `vterm'."
;;     (interactive)
;;     (setq compile-command (compilation-read-command compile-command))
;;     (let ((vterm-toggle-use-dedicated-buffer t)
;;           (vterm-toggle--vterm-dedicated-buffer (if (vterm-toggle--get-window)
;;                                                     (vterm-toggle-hide)
;;                                                   vterm-compile-buffer)))
;;       (with-current-buffer (vterm-toggle-cd)
;;         (setq vterm-compile-buffer (current-buffer))
;;         (rename-buffer "*vterm compilation*")
;;         (compilation-shell-minor-mode 1)
;;         (vterm-send-M-w)
;;         (vterm-send-string compile-command t)
;;         (vterm-send-return)))))

(use-package color-rg
  :ensure (:host github :repo "manateelazycat/color-rg")
  :config
  (with-eval-after-load 'evil
    (add-to-list 'evil-emacs-state-modes 'color-rg-mode)
    (define-key color-rg-mode-map (kbd "C-g") 'evil-multiedit-abort)
    (define-key color-rg-mode-edit-map (kbd "C-c :") 'evil-ex)
    (define-key color-rg-mode-edit-map (kbd "C-g") 'evil-multiedit-abort)
)
  )

(provide 'init-tools)
;;; init-tools.el ends here
